/*******************************************************************************
 * @(#)SimpleCookieManager.java 2019年08月29日 17:11
 * Copyright 2019 upbos.com. All rights reserved.
 *******************************************************************************/

package com.upbos.sso.cookie;

import com.upbos.core.util.CookieUtils;
import com.upbos.sso.Constants;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * <b>Application name：</b> SimpleCookieManager.java <br>
 * <b>Application describing： </b> <br>
 * <b>Copyright：</b> Copyright &copy; 2019 upbos.com 版权所有。<br>
 * <b>Company：</b> upbos.com <br>
 * <b>@Date：</b> 2019年08月29日 17:11 <br>
 * <b>@author：</b> <a href="mailto:Jason@miyzh.com"> Jason </a> <br>
 * <b>@version：</b>V5.0.0 <br>
 */
public class SimpleCookieManager implements CookieManager {


    private boolean httpOnly = false;

    private int maxAge = -1;

    private boolean rememberMe = false;

    private String tokenIdName = Constants.TOKEN_ID_COOKIE_NAME;

    @Override
    public void setHttpOnly(Boolean httpOnly) {
        this.httpOnly = httpOnly;
    }

    @Override
    public void setMaxAge(Integer maxAge) {
        this.maxAge = maxAge;
    }

    @Override
    public void setRememberMe(Boolean rememberMe) {
        this.rememberMe = rememberMe;
    }

    @Override
    public void setTokenIdName(String sid) {
        this.tokenIdName = sid;
    }

    @Override
    public String getTokenIdName() {
        return this.tokenIdName;
    }


    @Override
    public void setCookie(HttpServletResponse response, String tokenId) {
        CookieUtils.setCookie(response, this.tokenIdName, tokenId, this.maxAge, this.httpOnly);
    }

    @Override
    public void removeCookie(HttpServletResponse response) {
        CookieUtils.removeCookie(response, this.tokenIdName);
    }

    @Override
    public String getTokenId(HttpServletRequest request) {
        return CookieUtils.getCookieValue(request, this.tokenIdName);
    }

}
